<%
'/**
' * listen action from the site 
' *
' * @type : class
' * @author : [BI]CJJ http://www.imcjj.com
' * @date : 2007-06-05
' * @memo : 
' */
Class TAction
    'Private members
    Private cls_sMsg
    Private cls_aValids()
    'public members
    Public actionType

    Private Sub Class_Initialize()
       cls_sMsg = ""
       actionType = "FORM"
    End Sub

    Private Sub Class_Teminate()
    End Sub
 
    '/**
    ' * add the rule of validate
    ' *
    ' * @type : public method
    ' * @parameters : a_sValue, the parameter value
    ' *               a_sType, the type of validate
    ' *               a_sMsg,  the message to user of validate failed
    ' * @return : none
    ' * @author : [BI]CJJ http://www.imcjj.com
    ' * @date : 2007-06-05
    ' * @memo :
    ' */   
    Public Sub addValidRule(ByVal a_sValue, ByVal a_sType, ByVal a_sMsg)
        Dim iCount : iCount = UBound(cls_aValids)

        If iCount>0 Then
            cls_aValids(i+1)=a_sValue & "|" & a_sType & "|" & a_sMsg
        Else
            cls_aValids(0)=a_sValue & "|" & a_sType & "|" & a_sMsg 
        End If
    End Sub

    '/**
    ' * get the value valid result
    ' *
    ' * @type : private method
    ' * @parameters : a_sName, the parameter name 
    ' *               a_sType, the type of parameter value
    ' *               a_sValid, the valid method of parameter value
    ' *               a_sMsg, if the value is validate,that show the message to user
    ' * @return : the parameter value
    ' * @author : [BI]CJJ http://www.imcjj.com
    ' * @date : 2007-06-05
    ' * @memo :
    ' */    
    Public Sub Valid()
        Dim sTemp, sValid, sMsg, sValue
        Dim iPos, iTemp, i
        Dim aValids

        For i=0 To UBound(cls_aValids)
            aValids = Split(cls_aValids(i),"|")
            sValue = aValids(1)
            sMsg = aValids(2)
      
            Select Case LCase(sValid)
            Case "notnull"
                 If isNull(sValue) Then cls_sMsg=cls_sMsg & sMsg & "|" End If
            Case "email"
                 iPos = InstrRev(sValue, "@")
                 iTemp = InstrRev(sValue,".")

                 If Not (iPos>0 And iTemp>0) Then
                     cls_sMsg=cls_sMsg & sMsg & "|"
                     Exit Sub
                End If

                If iPos>=iTemp Then cls_sMsg=cls_sMsg & sMsg & "|" End If
            Case "cardid"
                iTemp = Len(sValue)

                Select Case iTemp
                Case 15
                    If Not isNumeric(sValue) Then cls_sMsg=cls_sMsg & sMsg & "|" End If
                Case 18
                    If Not isNumeric(Left(sValue,17)) Then
                       cls_sMsg=cls_sMsg & sMsg & "|"
                       Exit Sub
                   End If

                   sTemp = Right(sValue,1)
               
                   If Not isNumeric(sTemp) And LCase(sTemp)<>"x" Then cls_sMsg=cls_sMsg & sMsg & "|" End If
                Case Else
                    cls_sMsg=cls_sMsg & sMsg & "|"
                End Select
            Case "tel","fax"
                For iTemp=1 To Len(sValue)
                    sTemp = Mid(sValue,i,1)

                    If Not isNumeric(sTemp) And sTemp<>"-" Then
                        cls_sMsg=cls_sMsg & sMsg & "|"
                        Exit For
                    End If
                Next
            Case "zip"
                If Not isNumeric(sValue) Or Len(sValue)<>6 Then cls_sMsg=cls_sMsg & sMsg & "|" End If
            Case "mobile"
                If Not isNumeric(sValue) Or Len(sValue)<>11 Then cls_sMsg=cls_sMsg & sMsg & "|" End If
            Case "number"
                If Not isNumeric(sValue) Then cls_sMsg=cls_sMsg & sMsg & "|" End If
            Case Else
                Exit Sub
            End Select
        Next
    End Sub

    '/**
    ' * get the message of class
    ' *
    ' * @type : public method
    ' * @parameters : none
    ' * @author : [BI]CJJ http://www.imcjj.com
    ' * @date : 2007-06-05
    ' * @memo :
    ' */
    Public Function getMessage()
        getMessage = null
        If isNone(cls_sMsg) Then Exit Function End If
        getMessage = Left(cls_sMsg, Len(cls_sMsg)-1)
    End Function

    '/**
    ' * get all of the parameters from form or url
    ' *
    ' * @type : public method
    ' * @parameters : none
    ' * @return : all the value of parameters
    ' * @author : [BI]CJJ http://www.imcjj.com
    ' * @date : 2007-06-05
    ' * @memo :
    ' */
    Public Function getRequests()
        If actionType="URL" Then
            getRequests=Replace(Request.QueryString(),"'","''")
        Else
            getRequests=Request.Form()
        End If
    End Function

    '/**
    ' * get all of the parameters from form or url
    ' *
    ' * @type : public method
    ' * @parameters : a_sVarNames, server variables name list
    ' * @return : all the value of parameters
    ' * @author : [BI]CJJ http://www.imcjj.com
    ' * @date : 2007-06-05
    ' * @memo :
    ' */
    Public Function getServerVariables(ByVal a_sVarNames)
        Dim aNames : aNames = Split(a_sVarNames, ",")
        Dim i
        Dim aResults

        For i=0 To UBound(aNames)
            aResults(i) = Request.ServerVariables(aNames(i))
        Next

        getServerVariables = aResults
    End Function

    '/**
    ' * get the the value of parameter submit by get or post method
    ' *
    ' * @type : public method
    ' * @parameters : a_sName, the parameter name 
    ' *               a_sType, the type of parameter value
    ' * @return : the parameter value
    ' * @author : [BI]CJJ http://www.imcjj.com
    ' * @date : 2007-06-05
    ' * @memo :
    ' */    
    Public Function getRequest(ByVal a_sName, Byval a_sType)
        Dim vValue, vResult

        getRequest = Null

        If actionType="URL" Then
            vValue = Trim(Request.QueryString(a_sName))
        Else
            vValue = Trim(Request.Form(a_sName))
        End If

        If isNone(vValue) Then  Exit Function  End If
        
        Select Case LCase(a_sType)
        Case "integer"
            If Not IsNumeric(vValue) Then Exit Function  End If
            vResult = Int(vValue)
        Case "string"
           vResult = vValue
        Case "datetime"
            If Not IsDate(vValue) Then Exit Function End If
            vResult=CDate(vValue)
        Case "boolean"
            If TypeName(vValue)<>"Boolean" Then Exit Function End If
            vResult = false
            If (vValue) Then vResult=true End If
        End Select

        getRequest = vResult
    End Function
End Class
%>
